package 多线程;


/**
 *
 * 贡献资源
 * */
public class Web12306 implements Runnable {
    //票数
    private int ticketNum=99;
    @Override
    public void run() {
        while (true){
            if (ticketNum<0){
                break;
            }
            System.out.println(Thread.currentThread().getName() +"卖出一张票；剩余票数"+ticketNum--);
        }
    }

    public static void main(String[] args) {
        //一个资源
        Web12306 w = new Web12306();
        //多个代理（多个线程操作同一资源）
        new Thread(w,"一号窗口").start();
        new Thread(w,"二号窗口").start();
        new Thread(w,"三号窗口").start();

        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName() +"打酱油的主函数");
        }

    }

}
